package com.example.mvc.controller;

import com.example.mvc.bean.Brand;
import com.example.mvc.service.BrandService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/getBrandById")
public class GetBrandById  extends HttpServlet {
    private BrandService service = new BrandService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 接收id
        String id = req.getParameter("id");
        //2. 调用service查询
        Brand brand = service.getBrandById(Integer.parseInt(id));
        //3. 存储到request中
        req.setAttribute("brand",brand);
      //4. 转发到update.jsp
        req.getRequestDispatcher("/update.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
